﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Syngine.Components.Shapes
{
	/// <summary>
	/// 
	/// </summary>
	public class DrawableCircle : Shape
	{
		#region Fields

		private Vector2 _position;
		private float _radius;

		#endregion

		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="DrawableCircle"/> class.
		/// </summary>
		/// <param name="position">The position.</param>
		/// <param name="radius">The radius.</param>
		/// <param name="color">The color.</param>
		public DrawableCircle(Vector2 position, float radius, Color color) : base(color)
		{
			_position = position;
			_radius = radius;
		}

		#endregion

		#region Properties

		/// <summary>
		/// Gets or sets the position.
		/// </summary>
		/// <value>
		/// The position.
		/// </value>
		public Vector2 Position
		{
			get
			{
				return _position;
			}
			set
			{
				_position = value;

				InitializeCore();
			}
		}

		/// <summary>
		/// Gets or sets the radius.
		/// </summary>
		/// <value>
		/// The radius.
		/// </value>
		public float Radius
		{
			get
			{
				return _radius;
			}
			set
			{
				_radius = value;

				InitializeCore();
			}
		}

		#endregion

		#region Methods

		protected override void InitializeCore()
		{
			Vertices = new VertexPositionColor[100];

			for (var i = 0; i < 99; i++)
			{
				var angle = (float)(i / 99.0d * Math.PI * 2);
				Vertices[i].Position = new Vector3(Position.X + (float)Math.Cos(angle) * Radius, Position.Y + (float)Math.Sin(angle) * Radius, 0);
				Vertices[i].Color = Color;
			}

			Vertices[99] = Vertices[0];
		}

		#endregion
	}
}
